function objFactory() {
    let obj = {};  // 1. 创建一个空对象
    let temp = Array.prototype.shift.call(arguments);
    console.log()
    obj.__proto__ = temp.prototype; // 2 . 链接原型
    let tempResult = temp.apply(obj, arguments) // 3. 绑定this

    let result;
    if (Object.prototype.toString.call(tempResult).slice(8, -1) === 'Object') {
        result = tempResult
    } else {
        result = obj
    }
    return result  // 4. 确保返回一个对象
}

function animte(name) {
    this.name = name;
    this.habit = 'dog'
    return {
        age: 1
    }
}

animte.prototype.say = function () {
    console.log('i am ' + this.name)
}



// let dog = objFactory(animte,'dog')
let dog = new animte('dog')
dog.say()
console.log(dog)
